package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.ContractBaseEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 新工单-回执单枚举
 *
 * @author WuHB
 * @date 2021/11/17 15:41
 */
@Getter
public enum ReceiptOrderEnum {

    // ==================== 基础信息 ====================
    BASE_INFO("other_1", "enum.receiptOrder.attrName.baseInfo", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 100, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 回执单编号
    RECEIPT_ORDER_NO("serialNo", "enum.receiptOrder.attrName.receiptOrderNo", "receiptOrderNo", FieldTypeEnum.SERIALNO.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 200, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 关联工单
    LINK_WORK_ORDER("text_1", "enum.receiptOrder.attrName.workOrderV2Id", "LinkWorkOrderV2", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 300, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 关联客户
    LINK_CUSTOMER("text_2", "enum.receiptOrder.attrName.customerId", "linkCustomer", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 400, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 回执信息
    RECEIPT_INFO("text_3", "enum.receiptOrder.attrName.receiptInfo", "receiptInfo", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 500, 1, 1, ScreenTypeEnum.SCREEN_SHOW.getType()),
    // ==================== 销售信息 ====================
    SALES_INFO("other_2", "enum.receiptOrder.attrName.salesInfo", "salesInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 600, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 关联产品
    PRODUCT("array_1", "enum.receiptOrder.attrName.product", "products", FieldTypeEnum.SELECT_PRODUCT.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 700, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 服务项目
    SERVICE_PROJECT("array_2", "enum.receiptOrder.attrName.serviceProject", "serviceProject", FieldTypeEnum.SELECT_SERVICE.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 800, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 产品合计
    PRODUCT_TOTAL("num_1", "enum.receiptOrder.attrName.productTotal", "productTotal", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 900, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 服务项目合计
    SERVICE_TOTAL("num_2", "enum.receiptOrder.attrName.servicesTotal", "serviceTotal", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 1000, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 总费用
    TOTAL_AMOUNT("num_3", "enum.receiptOrder.attrName.totalAmount", "totalAmount", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 1100, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 毛利
    GROSS_MARGIN("num_4", "enum.receiptOrder.attrName.grossMargin", "grossMargin", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.LIST_DETAIL.getCode(), 1110, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 负责人
    OWNER_ID("ownerId","enum.receiptOrder.attrName.ownerId", "ownerId", FieldTypeEnum.OWNERID.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 1200, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 协同人
    MINOR_USER("coUserId", "enum.receiptOrder.attrName.minorUser", "coUserId", FieldTypeEnum.COUSERID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 1300, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    // 结算状态
    SETTLE_STATUS("text_5", "enum.receiptOrder.attrName.settleStatus", "settleStatus", FieldTypeEnum.COMBO.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 1310, 0, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // ==================== 系统信息 ====================
    SYSTEM_INFO("other_3", "enum.receiptOrder.attrName.systemInfo", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 1400, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 创建人
    CREATOR_ID("creatorId", "enum.receiptOrder.attrName.creatorId", "creatorId", FieldTypeEnum.CREATORID.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1500, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 创建时间
    ADD_TIME("addTime", "enum.receiptOrder.attrName.addTime", "addTime", FieldTypeEnum.ADDTIME.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 1600, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 修改时间
    UPDATE_TIME("updateTime", "enum.receiptOrder.attrName.updateTime", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 1700, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // ==================== 隐藏字段 ====================
    // 关联客户隐藏
    LINK_CUSTOMER_HIDE("text_50", "enum.receiptOrder.attrName.linkCustomerHide", "linkCustomerHide", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9470, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 关联工单隐藏
    LINK_WORK_ORDER_HIDE("text_51", "enum.receiptOrder.attrName.linkWorkOrderHide", "linkWorkOrderHide", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9470, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 总成本
    TOTAL_COST("num_52", "enum.receiptOrder.attrName.totalCost", "totalCost", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9480, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    ;

    ReceiptOrderEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                     Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache
     * @return
     */
    public static String getAttrConnectData(ReceiptOrderEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * @description 默认标签
     * @param
     * @return java.util.List<java.lang.Object>
     *
     * @creator jiantao.xiong
     * @date 2019/12/18 15:00
     *
     */
    public static List<Object> getLabelAttrList() {
        return Arrays.asList();
    }

    /**
     * app端详情默认标题显示字段
     */
    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(RECEIPT_ORDER_NO);
    }
    /**
     * app端详情默认标题显示字段
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(LINK_CUSTOMER, LINK_WORK_ORDER, OWNER_ID, ADD_TIME);
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }

    public static List<String> getNonEditableList() {
        return Arrays.asList(PRODUCT.getAttr(),CREATOR_ID.getAttr());
    }
    public static List<String> getNonEditableAttr() {
        return Arrays.asList(LINK_WORK_ORDER.getAttr(),LINK_CUSTOMER.getAttr(), PRODUCT_TOTAL.getAttr(), SERVICE_TOTAL.getAttr());
    }

    public static String getEsAttr4Keyword(ReceiptOrderEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }
}
